import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

@Slf4j
public class DefaultSocketServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8080);
        while (true) {
            Socket socket = serverSocket.accept();
            sendHttpContent(socket);
        }
    }

    public static void sendHttpContent(Socket socket) throws IOException {

        OutputStream outputStream = socket.getOutputStream();

        String content = "Hello World my custom socket server";

        PrintWriter writer = new PrintWriter(outputStream);
        writer.println("HTTP/1.1 200 OK");
        writer.println("Server: Nginx");
        writer.println("Content-Type: text/html;charset=UTF-8");
        writer.println("Content-Length: " + content.length());
        writer.println("Connection: keep-alive");
        writer.println("");
        writer.println(content);

        writer.flush();
        writer.close();

        socket.close();
    }

}
